<template>
	<view class="body-view">
		<!--导航和状态栏-->
		<view class="state-navigation">
			<view class="slim_header_navigation d-flex a-center j-center" >
				<view class="left_box" @tap="goBack">
					<image src="/static/center/back.png" class="back"></image>
				</view>
				<view>
					<view class="title" style="text-align: center;">饮食打卡</view>
					<view class="group-name">{{groupInfo?.name}}</view>
				</view>
				<view class="right_box">
					<!-- <image src="/static/center/dian.png" class="dian"></image> -->
				</view>
			</view>
		</view>
		<!-- 顶部位置占位 -->
		<view style="height:calc(100rpx + var(--status-bar-height));"></view>
		<!--顶部菜单和搜索-->
		<view class="top-search">
			<view class="top-search-menu d-flex a-center j-between">
				<view class="menu-tabs d-flex a-center">
					<view v-for="(item,index) in tabs" class="menu-tabs-bottom">
						<view @tap="changeTabs(index)" :class="`menu-tabs-text ${index==menuSelect?'menu-select':''}`">{{item}}</view>
						<view v-if="index==menuSelect" class="menu-tabs-background"></view>
						<view v-if="showTabsMark(index)" class="menu-tabs-mark"></view>
					</view>
				</view>
				<view class="search-date d-flex a-center j-center" @tap="showDateTable">
					<view class="date-content">{{moment(selectDate).format("M月D日")}}<br>{{moment(selectDate).locale('zh-cn').format('dddd')}}</view>
					<image class="date-drop" src="@/static/image/drop-down.png"></image>
				</view>
			</view>
			<view class="top-search-search d-flex a-center">
				<view class="search-input d-flex a-center">
					<view class="input-icon d-flex a-center">
						<image
                            style="width: 30rpx; height: 30rpx"
                            src="/static/nvue/search.png"
                            mode=""
                        />
					</view>
					<!--
					<view class="input-input">搜索食物</view>
					-->
					<input class="inp" type="text" v-model="searchText" placeholder-style="color:#ccc" placeholder="搜索食物">
					<i v-if="searchText" @tap="searchText=''" class="tmicon tmicon-times-circle-fill" style="color:#c4c4c4;"></i>
				</view>
			</view>
		</view>
		<view class="classification d-flex">
			<view class="left-class heights">
				<view v-for="(item,index) in pageData" class="class-cell d-flex a-center j-center">
					<view @tap="chooseClass(index)" :class="`${selectClass==index?'class-cell-true':'class-cell-false'}`">
						<template v-if="item.code=='8888888'">
							<i class="icon icon-wodefangan" :style="{fontSize: '34rpx',color:selectClass==index?'#ffffff':'#1DC691'}"></i>
						</template>
						<template v-else>{{item.name}}</template>
					</view>
				</view>
			</view>
			<view class="right-class heights">
				<scroll-view v-for="(item,index) in pageData" :key="item.id" v-show="!searchText&&index==selectClass" scroll-y="true" class="heights">
					<template v-if="item.code=='9999999'">
						<view class="class-row-title">收藏{{item?.childNode?.filter((node:any) => node.note == 0).length==0?'（暂无）':''}}</view>
						<template v-for="items in item?.childNode" :key="items.id">
							<view v-if="items.note==0" class="class-row d-flex">
								<view class="class-row-icon">
									<view v-if="items.healthLight=='1'||items.healthLight==null" class="row-fire" style="background: #1DC691;"></view>
									<view v-if="items.healthLight=='2'" class="row-fire" style="background: #FFAF67;"></view>
									<view v-if="items.healthLight=='3'" class="row-fire" style="background: #FF5831;"></view>
								</view>
								<view  class="class-row-content"  @tap="showAddCart(items)">
									<view class="row-name">{{items.name}}</view>
									<view class="row-consume d-flex">
										<text>{{items.heat}}千卡/</text>
										<text v-if="items.isLiquid=='0'">100g</text>
										<text v-if="items.isLiquid=='1'">100ml</text>
									</view>
								</view>
								<view class="class-row-check d-flex a-center j-end"  @tap="onCheck(items)">
									<image v-if="items.isCheck" class="row-check" src="@/static/image/diet-menu-check-true.png"></image>
									<image v-else class="row-check" src="@/static/image/sports-menu-check-false.png"></image>
								</view>
							</view>
						</template>
						<view class="class-row-title">常用{{item?.childNode?.filter((node:any) => node.note == 1).length==0?'（暂无）':''}}</view>
						<template v-for="items in item?.childNode" :key="items.id">
							<view v-if="items.note==1" class="class-row d-flex">
								<view class="class-row-icon">
									<view v-if="items.healthLight=='1'||items.healthLight==null" class="row-fire" style="background: #1DC691;"></view>
									<view v-if="items.healthLight=='2'" class="row-fire" style="background: #FFAF67;"></view>
									<view v-if="items.healthLight=='3'" class="row-fire" style="background: #FF5831;"></view>
								</view>
								<view class="class-row-content" @tap="showAddCart(items)">
									<view class="row-name">{{items.name}}</view>
									<view class="row-consume d-flex">
										<text>{{items.heat}}千卡/</text>
										<text v-if="items.isLiquid=='0'">100g</text>
										<text v-if="items.isLiquid=='1'">100ml</text>
									</view>
								</view>
								<view class="class-row-check d-flex a-center j-end" @tap="onCheck(items)">
									<image v-if="items.isCheck" class="row-check" src="@/static/image/diet-menu-check-true.png"></image>
									<image v-else class="row-check" src="@/static/image/sports-menu-check-false.png"></image>
								</view>
							</view>
						</template>
					</template>
					<template v-else>
						<view v-for="items in item?.childNode" :key="items.id" class="class-row d-flex">
							<view class="class-row-icon">
								<view v-if="items.healthLight=='1'||items.healthLight==null" class="row-fire" style="background: #1DC691;"></view>
								<view v-if="items.healthLight=='2'" class="row-fire" style="background: #FFAF67;"></view>
								<view v-if="items.healthLight=='3'" class="row-fire" style="background: #FF5831;"></view>
							</view>
							<view class="class-row-content" @tap="showAddCart(items)">
								<view class="row-name">
									{{items.name}}
									<template v-if="item.code=='8888888'">
										<text class="programme-mark" style="background: #1DC691;" v-if='items.note==1'>早</text>
										<text class="programme-mark" style="background: #FFA350;" v-if='items.note==2'>午</text>
										<text class="programme-mark" style="background: #7648F7;" v-if='items.note==3'>晚</text>
										<text class="programme-mark" style="background: #4888F7;" v-if='items.note==4'>加</text>
									</template>
								</view>
								<view class="row-consume d-flex" >
									<text>{{items.heat}}千卡/</text>
									<template v-if="item.code=='6666666'||item.code=='8888888'">
										<text>{{items.unitNumber}}{{items.unit}}</text>
									</template>
									<template v-else>
										<text v-if="items.isLiquid=='0'">100g</text>
										<text v-if="items.isLiquid=='1'">100ml</text>
									</template>
								</view>
							</view>
							<view class="class-row-check d-flex a-center j-end" @tap="onCheck(items)">
								<image v-if="items.isCheck" class="row-check" src="@/static/image/diet-menu-check-true.png"></image>
								<image v-else class="row-check" src="@/static/image/sports-menu-check-false.png"></image>
							</view>
						</view>
					</template>
				</scroll-view>
				
				<scroll-view v-show="searchText" scroll-y="true" class="heights">
						<view v-for="items in search_childNode" :key="'search'+items.id" class="class-row d-flex">
							<view class="class-row-icon">
								<view v-if="items.healthLight=='1'||items.healthLight==null" class="row-fire" style="background: #1DC691;"></view>
								<view v-if="items.healthLight=='2'" class="row-fire" style="background: #FFAF67;"></view>
								<view v-if="items.healthLight=='3'" class="row-fire" style="background: #FF5831;"></view>
								
							</view>
							<view class="class-row-content" @tap="showAddCart(items)">
								<view class="row-name">
				                    <rich-text :nodes="items.nodes"></rich-text>
				                </view>
								<view class="row-consume d-flex">
									<text>{{items.heat}}千卡/</text>
									<text v-if="items.isLiquid=='0'">100g</text>
									<text v-if="items.isLiquid=='1'">100ml</text>
								</view>
							</view>
							<view class="class-row-check d-flex a-center j-end" @tap="onCheck(items)">
								<image v-if="items.isCheck" class="row-check" src="@/static/image/diet-menu-check-true.png"></image>
								<image v-else class="row-check" src="@/static/image/sports-menu-check-false.png"></image>
							</view>
						</view>
				</scroll-view>
			</view>
		</view>
		<view class="diet-add d-flex a-center j-center">
			<view @tap="showAddCustom" class="d-flex a-center j-center">
				<view class="add-icon d-flex a-center j-center" :style="{background: addDisable?'#ABABAB':'#23E2A6' }">
					<i class="icon icon-a-" style="color:#ffffff;font-size:36rpx;"></i>
				</view>
				<view class="add-text">添加自定义食物</view>
			</view>
		</view>
		<view class="diet-button d-flex j-between">
			<view class="d-flex" @tap="showCheck">
				<uni-badge :text="dietCart.length" absolute="rightTop" :offset="[7, 7]" :custom-style="{backgroundColor:'#FF5831'}" size="normal">
					<i v-if="menuSelect===0" class="icon icon-zaocan" style="color:#23E2A6;font-size:80rpx;"></i>
					<i v-if="menuSelect===1" class="icon icon-wucan" style="color:#23E2A6;font-size:80rpx;"></i>
					<i v-if="menuSelect===2" class="icon icon-wancan" style="color:#23E2A6;font-size:80rpx;"></i>
					<i v-if="menuSelect===3" class="icon icon-jiacan" style="color:#23E2A6;font-size:80rpx;"></i>
				</uni-badge>
				<view class="button-content">
					<view class="button-type">{{tabs[menuSelect]}}</view>
					<view v-if="dietCart.length>0" class="button-text">共{{dietCart.length}}项食物({{cartHeat}}千卡)</view>
					<view v-else class="button-text">还未添加</view>
				</view>
			</view>
				<tm-button :disabled="addDisable"  _style="margin-top: -6rpx;font-weight: 600;" round="5" :width="260" :height="80" :shadow="-1"
				    color="#23E2A6" disabled-color="#ABABAB" :fontSize="32" fontColor="#ffffff" @tap="submit"
				    label="打卡"></tm-button>
		</view>
		<!--阴影层-->
		<view class="diet-shadow"></view>
		<!--食物编辑-->
		<uni-popup ref="editPopup" :safe-area="false" type="bottom" @change="editChange">
			<view class="popup-edit">
				<view class="edit-name d-flex a-center">
					<!--
					<view class="edit-name-icon"></view>
					-->
					<view v-if="editDiet.healthLight=='1'||editDiet.healthLight==null" class="edit-name-icon" style="background: #1DC691;"></view>
					<view v-if="editDiet.healthLight=='2'" class="edit-name-icon" style="background: #FFAF67;"></view>
					<view v-if="editDiet.healthLight=='3'" class="edit-name-icon" style="background: #FF5831;"></view>
					<view class="edit-name-content" @tap="goFoodDetail(editDiet.code)">
						<view class="edit-name-text">{{editDiet.name}}<image src="/static/Information/right-b.png" class="right-b"/></view>
						<view class="edit-name-describe">{{getUnitJson(editDiet.unitUnit)?.heat}}千卡/{{getUnitJson(editDiet.unitUnit)?.measure}}{{editDiet.unitUnit}}</view>
					</view>
					<view class="edit-collect d-flex a-center j-end">
						<view class="d-flex a-center" @tap="onCollect" >
							<image class="edit-collect-icom" v-if="editDiet.isCollect" src="@/static/image/diet-collect-yes.png"></image>
							<image class="edit-collect-icom" v-else src="@/static/image/sports-collect-no.png"></image>
							<text class="edit-collect-text">收藏</text>
						</view>
					</view>
				</view>
				<view class="edit-component">
					<view class="edit-component-content d-flex">
						<view class="component-content-cell">
							<view class="component-content-title">纤维素</view>
							<view class="component-content-number">
								<template v-if="editDiet.cellulose==null">-</template>
								<template v-else>{{editDiet.cellulose}}g</template>
							</view>
						</view>
						<view class="component-content-cell">
							<view class="component-content-title">碳水化合物</view>
							<view class="component-content-number">
								<template v-if="editDiet.carbWater==null">-</template>
								<template v-else>{{editDiet.carbWater}}g</template>
							</view>
						</view>
						<view class="component-content-cell">
							<view class="component-content-title">蛋白质</view>
							<view class="component-content-number">
								<template v-if="editDiet.protein==null">-</template>
								<template v-else>{{editDiet.protein}}g</template>
							</view>
						</view>
						<view class="component-content-cell">
							<view class="component-content-title">脂肪</view>
							<view class="component-content-number">
								<template v-if="editDiet.fat==null">-</template>
								<template v-else>{{editDiet.fat}}g</template>
							</view>
						</view>
					</view>
				</view>
				<view class="edit-input">
					<view style="flex: 1;"></view>
					<view>
						<view class="edit-input-time d-flex j-center">
							<view class="input-time-text">{{editEatGrams}}</view>
						</view>
						<view class="edit-input-describe">热量约{{editHeat}}千卡</view>
					</view>
					
					<view class="input-describe">
						<view class="input-describe-text">{{countDescribe()}}</view>
					</view>
					
				</view>
				<view class="edit-unit">
					<transverse :unit="editDiet.unitUnit" :unitList="editDiet.unitList" @onResult="getUnit"></transverse>
					<!--unit-text-select-->
					<!--
					<scroll-view class="edit-unit-scroll" scroll-x="true">
						<view v-for="item in editDiet.unitList" @tap="changeUnit(item)" :class="`edit-unit-text ${editDiet.unitUnit==item.dw?'unit-text-select':''}`">{{item.dw}}</view>
					</scroll-view>
					-->
				</view>
				<view class="edit-keyboard d-flex j-between wrap">
					<view @touchstart="count('1')" class="edit-keyboard-button">1</view>
					<view @touchstart="count('2')" class="edit-keyboard-button">2</view>
					<view @touchstart="count('3')" class="edit-keyboard-button">3</view>
					<view @touchstart="count('4')" class="edit-keyboard-button">4</view>
					<view @touchstart="count('5')" class="edit-keyboard-button">5</view>
					<view @touchstart="count('6')" class="edit-keyboard-button">6</view>
					<view @touchstart="count('7')" class="edit-keyboard-button">7</view>
					<view @touchstart="count('8')" class="edit-keyboard-button">8</view>
					<view @touchstart="count('9')" class="edit-keyboard-button">9</view>
					<view style="width: 210rpx;"></view>
					<view @touchstart="count('0')" class="edit-keyboard-button">0</view>
					<view @touchstart="count('del')" class="edit-keyboard-button d-flex a-center j-center">
						<image class="keyboard-button-image" src="@/static/image/keyboard-del.png"></image>
					</view>
				</view>
				<view class="confirm-button d-flex j-center">
					<tm-button _style="margin-top: -6rpx;font-weight: 600;" round="5" :width="690" :height="80" :shadow="-1"
					    :linear-color="['#64F1C5', '#29DBA3']" linear="left" :fontSize="32" fontColor="#ffffff" @tap="addCart"
					    label="确定"></tm-button>
				</view>
			</view>
		</uni-popup>
		<!--购物车-->
		<uni-popup ref="checkPopup" :safe-area="false" type="bottom" style="z-index: 85;">
			<view class="checkPopup">
				<scroll-view scroll-y="true" style="max-height: 700rpx;">
					<view v-for="item in dietCart" class="checkPopup-row d-flex j-end">
						<view class="checkPopup-row-cell d-flex a-center">
							<view v-if="item.healthLight=='1'||item.healthLight==null" class="checkPopup-row-fire" style="background: #1DC691;"></view>
							<view v-if="item.healthLight=='2'" class="checkPopup-row-fire" style="background: #FFAF67;"></view>
							<view v-if="item.healthLight=='3'" class="checkPopup-row-fire" style="background: #FF5831;"></view>
							<view class="checkPopup-row-name">{{item.name}}</view>
						</view>
						<view class="checkPopup-row-content d-flex a-center j-end">
							<view class="checkPopup-row-time">{{item.unit}}{{item.unitUnit}}</view>
							<image v-if="!addDisable"  @tap="showEdit(item)" class="checkPopup-row-edit" src="@/static/image/dietPopup-edit.png"></image>
						</view>
						<view class="checkPopup-row-button d-flex a-center j-end">
							<view class="checkPopup-row-calorie">{{item.heat}}千卡</view>
							<image v-if="!addDisable" @tap="delCheck(item)" class="checkPopup-row-del" src="@/static/image/checkPopup-del.png"></image>
						</view>
					</view>
				</scroll-view>
				<view :class="`checkPopup-upload d-flex ${imageUrlList.length==0?'j-center':''}`">
					<view  class="checkPopup-upload-image" v-for="(item,index) in imageUrlList">
						<image @tap="previewImage('preview',index,imageUrlList)" :id="`preview${index}`" class="upload-image-img" mode="aspectFill" :src="item"></image>
						<view class="upload-image-del d-flex a-center j-center">
							<image @tap="delImage(index)" class="image-del-icon" src="@/static/image/upload-image-del.png"></image>
						</view>
					</view>
					<view v-if="imageUrlList.length<4&&!addDisable" class="upload-cell-button" @tap="imageUpload">
						<image class="cell-content-icon" src="@/static/image/checkPopup-camera.png"></image>
						<view class="cell-content-text">上传照片</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<!--自定义饮食添加-->
		<uni-popup ref="addPopup" :safe-area="false" type="bottom">
			<view class="popup-add" :style="{transform: 'translateY(-'+ keyBoardHeight +'px)'}">
				<viue class="popup-title d-flex a-center j-center">
					<view class="title-text">添加自定义食物</view>
					<image @tap="addPopup.close()" class="title-icon" src="@/static/image/close.png"></image>
				</viue>
				<view class="form-add">
					<uni-forms ref="addForm" err-show-type="toast" :modelValue="addFormData" :rules="addRules">
						<uni-forms-item name="name">
							<view class="forms-item d-flex a-center">
								<view class="forms-item-label">食物名</view>
								<input :adjust-position="false" class="forms-item-input" v-model="addFormData.name"/>
							</view>
						</uni-forms-item>
						<uni-forms-item name="unit">
							<view class="forms-item d-flex a-center">
								<view class="forms-item-label">单位</view>
								<input :adjust-position="false" type="number" class="forms-item-input" v-model="addFormData.unit" style="width: 227rpx;"/>
								<view class="add-radio d-flex">
									<view @tap="addFormData.unitUnit='克'" :class="`add-radio-cell ${addFormData.unitUnit=='克'?'add-radio-yes':''}`">克</view>
									<view @tap="addFormData.unitUnit='个'" :class="`add-radio-cell ${addFormData.unitUnit=='个'?'add-radio-yes':''}`">个</view>
									<view @tap="addFormData.unitUnit='拳'" :class="`add-radio-cell ${addFormData.unitUnit=='拳'?'add-radio-yes':''}`">拳</view>
									<view @tap="addFormData.unitUnit='碗'" :class="`add-radio-cell ${addFormData.unitUnit=='碗'?'add-radio-yes':''}`">碗</view>
								</view>
							</view>
						</uni-forms-item>
						<uni-forms-item name="heat">
							<view class="forms-item d-flex a-center">
								<view class="forms-item-label">总热量</view>
								<input :adjust-position="false" type="number" class="forms-item-input" v-model="addFormData.heat" style="width: 227rpx;"/>
								<view class="add-radio d-flex">
									<view @tap="editHeatUnit('千卡')" style="width: 170rpx;" :class="`add-radio-cell ${addFormData.heatUnit=='千卡'?'add-radio-yes':''}`">千卡</view>
									<view @tap="editHeatUnit('千焦')" style="width: 170rpx;" :class="`add-radio-cell ${addFormData.heatUnit=='千焦'?'add-radio-yes':''}`">千焦</view>
								</view>
							</view>
							<view class="forms-item-describe">
								{{addFormData.heatUnit=='千焦'?`最终记录时将换算成千卡，当前${heatConvert(addFormData.heat)}千卡`:''}}
							</view>
						</uni-forms-item>
					</uni-forms>
				</view>
				<view class="confirm-button d-flex j-center">
					<view class="confirm-describe"></view>
					<tm-button _style="margin-top: -6rpx;font-weight: 600;" round="5" :width="690" :height="80" :shadow="-1"
					    :linear-color="['#64F1C5', '#29DBA3']" linear="left" :fontSize="32" fontColor="#ffffff" @tap="addEditCustom"
					    label="确定"></tm-button>
				</view>
			</view>
		</uni-popup>
		<!--删除控件-->
		<uni-popup ref="popup" :safe-area="false">
		    <view class="sys-confirm-content">
				<view class="confirm-content-title">取消<text style="color: #1DC691;">&nbsp;{{delRow.name}}（{{delRow.unit}}{{delRow.unitUnit}}）</text>吗？</view>
				<view  @tap="delChoose" class="content-button button-confirm" style="color: #FD5745;">删除</view>
				<view style="height: 20rpx; background: #f5f5f5"></view>
				<view @tap="closePopup" class="content-button" style="color: #999999;">取消</view>
		    </view>
		</uni-popup>
		<!--日期选择-->
		<dateTable
			ref="datePopup"
			:markDate="markDate"
			:initialDate="selectDate"
			color="#1DC691"
			minDate="2023-1-1"
			:zIndex="402"
			:maxDate="moment().format('YYYY-MM-DD')"
			@onGetDate="onGetDate"
			@changeMoon="onChangeMoon">
		</dateTable>
		<imagePreview ref="preview" @onChange="imageChange"></imagePreview>
	</view>
</template>

<script setup lang="tsx" name="dietMenu">
import { ref,nextTick,watch } from 'vue';
import { onLoad,onShow,onHide } from '@dcloudio/uni-app';
import { 	getFoodList,//获取食物列表
			editFoodCollect,//收藏食物
			addGroupFoodRecord,//打卡（添加食物）
			getGroupFoodRecord,
			getGroupFoodDate,
			searchFood,
			getFavoritesFood,
			getCircleDetail
		} from "@/api/api";
import moment from "moment";
import "moment/dist/locale/zh-cn";
import { userData as userDataStore } from "@/store/userData";
import BigNumber from "bignumber.js";
import {showLoading,closeLoading} from '@/utils/utils';
import { BASE_URL } from "@/api/request";
import { imageConvertArray,getHDImages } from '@/utils/format';
import dateTable from "@/components/dateTable.vue";
import imagePreview from "@/components/imagePreview.vue";
import { chooseImage } from "@/utils/utils";
import transverse from "./components/transverse.vue";

const getUnit = (unit:string) => {
	if(unit=="克"){
		editEatGrams.value = 100
	}else{
		editEatGrams.value = 1
	}
	editDiet.value.unitUnit = unit
}


const goBack = () => {
	uni.navigateBack();
};
const userData: any = userDataStore();
const tabs = ref(["早餐","午餐","晚餐","加餐"]);
const menuSelect = ref(0);//选中的菜单
const selectClass = ref(1)//选中的分类
const markDate:any = ref([])//需要标识的日期
const isFoodRecordList = ref();//是否有对应的数据
const datePopup = ref();
const keyBoardHeight = ref(0);
const groupId = ref();//群ID
const groupInfo = ref();//群信息
let isLoad = false;//判断是否为首次进入
let isNullAdd = false;//内容为空时时候允许使用
onLoad((options:any)=>{

	isLoad = true;
	menuSelect.value = Number(options.type);//设置选中的菜单

    const obj = uni.getStorageSync('FOODDATA');
    if(obj){
        pageData.value = obj;
        selectClass.value = pageData.value.findIndex((item:any) => item.code=="9999999");
    }

	groupId.value = options.groupId;
	if(options.recordDate!=null)selectDate.value = options.recordDate;
	isAddDisable();//设置按钮是否可用
	loadPageData();
	getCircleDetail({groupId:groupId.value}).then((res:any) => {
		if(res.success){
			groupInfo.value = res.data;
		}
	});
});
onShow(() => {
	//处理键盘盖住文本框问题
	/* #ifndef H5 */
	uni.onKeyboardHeightChange(res => {
		keyBoardHeight.value = res.height;
	})
	/*#endif*/
});
onHide(() => {
	/* #ifndef H5 */
	uni.offKeyboardHeightChange(); 
	/*#endif*/
});
const editHeatUnit = (unit:string) => {
	addFormData.value.heatUnit = unit;
	if(addFormData.value.isEdit){
		if(unit == "千焦"){
			let i = Math.round(new BigNumber(addFormData.value.heat).div(new BigNumber(0.2389)).toNumber());
			if(isNaN(i))i=0;
			addFormData.value.heat = i 
			addFormData.value.foodHeat = i 
		}
		if(unit == "千卡"){
			let i = Math.round(new BigNumber(addFormData.value.heat).times(new BigNumber(0.2389)).toNumber());
			if(isNaN(i))i=0;
			addFormData.value.heat = i
			addFormData.value.foodHeat = i 
		}
	}
}
//是否显示tab右上角标识
const showTabsMark = (index:number) => {
	if(index==0&&isFoodRecordList.value?.breakfast>0)return true;
	if(index==1&&isFoodRecordList.value?.lunch>0)return true;
	if(index==2&&isFoodRecordList.value?.dinner>0)return true;
	if(index==3&&isFoodRecordList.value?.addFood>0)return true;
	return false;
}
//选中菜单变更时
const changeTabs = (index:number) =>{
	menuSelect.value = index;
	getDietRecord();
}
//日期选择
const onGetDate = (date:Date) => {
	selectDate.value = date;
	loadPageData();//重新加载数据
	isAddDisable();//设置按钮是否可用
}
//加载页面数据
const pageData:any = ref();
const loadPageData = () => {
	
	getFoodList({userId:userData.id}).then((res:any) => {
		let collectList = res.data.filter((item:any) => item.code=="9999999")[0].childNode.filter((node:any) => node.note == 0);
		res.data.forEach((item:any) => {
			item?.childNode.forEach((items:any) => {
				items.isCheck = false;//是否选中
				items.isCollect = false;//是否收藏
				let i = collectList.filter((node:any) => node.code == items.code);
				if(i.length>0)items.isCollect = true;
			})
		})
		pageData.value = res.data;
		selectClass.value = pageData.value.findIndex((item:any) => item.code=="9999999");
		getDietRecord();

        const arr = JSON.parse(JSON.stringify(res.data));


        arr.forEach((item:any) =>{
            if(item.code!=="9999999"){
                item.childNode = [];
            }
        })



        uni.setStorageSync('FOODDATA',arr)
	});
	
}
//切换选择的分类
const chooseClass = (index:number) =>{
	if(selectClass.value!==index){
	    searchText.value = '';
	}
	selectClass.value = index;
}
const selectDate:any = ref(new Date());//选中的日期
const dietCart:any = ref([]);//饮食购物车
const cartHeat = ref(0)//购物车总热量
const editEatGrams = ref();//编辑输入的数量
const editHeat = ref();//编辑计算的热量
//显示购物车添加页面
const editPopup = ref();//食物添加编辑页面
const editDiet = ref();//食物编辑
const showAddCart = (diet:any) => {	
	if(addDisable.value)return;
	if(diet.isLiquid==null){//自定义
		console.log(diet)
		if(diet.isCheck){
			for(let i=0;i<dietCart.value.length;i++){
				if(diet.name === dietCart.value[i].name){
					addFormData.value = dietCart.value[i];
					break;
				}
			}
		}else{
			addFormData.value = {
				name : diet.name,
				unit : diet.unitNumber,
				unitUnit : diet.unit,
				heat : diet.heat,
				heatUnit : "千卡",
				addType : 1
			}
		}
		addPopup.value.open();
	}else{
		editPopup.value.open();
		if(diet.isCheck){
			for(let i=0;i<dietCart.value.length;i++){
				if(diet.code === dietCart.value[i].code){
					editDiet.value = dietCart.value[i];
					break;
				}
			}
		}else{
			let param = JSON.parse(JSON.stringify(diet));
			param.unitList = getUnitList(param);
			param.addType = 0;//0系统添加，1自定义
			param.foodHeat = param.heat;
			param.unitUnit = param.unitList[0].dw;
			param.unit = 100;
			editDiet.value = param;
		}
		editEatGrams.value = editDiet.value.unit.toString();
		editHeat.value = editDiet.value.heat;
	}
	//adjustSort();
}
/*
//调整单位排序已中在最前面
const adjustSort= () => {
	if(editDiet.value.addType==0){
		let unitList = editDiet.value.unitList;
		let dw = editDiet.value.unitUnit;
		let index = unitList.findIndex((item:any) => item.dw==dw);
		if(index>-1){
			let elementToMove = unitList[index];
			unitList.splice(index, 1);  
			unitList.unshift(elementToMove);
		}
		//console.log(editDiet.value)
	}
}
*/
//计算出描述内容
const countDescribe = () =>{
	let describe = "";
	let results:any = editDiet.value?.unitList.filter((item:any) => item.dw === editDiet.value?.unitUnit);
	if(results.length>0)describe = results[0].count;
	let regex = /\d+(\.\d+)?/g; // 匹配所有的数字，包括可能存在的小数点  
	let newStr = describe.replace(regex, match => {  
		let num = Number(match);
		let i = 0;
		if(editEatGrams.value!=null&&editEatGrams.value!='')i = editEatGrams.value;
		return new BigNumber(num).times(new BigNumber(i)).toString();// 将结果再转换为字符串并加上单位  
	});  
	return newStr;
}
//根据食物据获取单位集合
const getUnitList = (data:any) => {
	//console.log(data);
	/*
	let param = JSON.parse(JSON.stringify(data));
	let s = param.unit;
	if(s==null||s=="")s = '[]';
	//console.log(s)
	let unitList = JSON.parse(s);
	
	unitList.forEach((item:any) => {
		item.measure = 1;
	});
	//默认单位
	let gram = {
		heat:param.heat,
		count:"",
		dw:"克",
		measure:100,
	}
	unitList.unshift(gram);
	*/
	let unitArray = []//data.unit.split("；");
	if(data.unit!=null&&data.unit!='')unitArray = data.unit.split("；");
	
	let unitList = [];
	unitList.push({
		heat:data.heat,
		count:'',
		dw:"克",
		measure:100,
	});
	if(unitArray.length>0){
		unitArray.forEach((item:string) => {
			let strArray = item.split(",");
			let array =  strArray[1].match(/\d+/g);
			let base = 0;
			if(array!=null&&array.length>0)base = Number(array[0]);
			//if(base==null)base = 0;
			unitList.push({
				heat:Number(Math.round(data.heat / 100 * base)),
				count:strArray.length>0?strArray[1]:'',
				dw:strArray[0].replace(/\d+/g, ''),
				measure:1,
			});
		});
	}
	return unitList;
}
//单位改变重新计算
const changeUnit = (data:any) => {
	editDiet.value.unitUnit = data.dw;
	let unitJson = getUnitJson(data.dw);
	//console.log(unitJson)
	editEatGrams.value = unitJson.measure;
	editHeat.value = unitJson.heat.toString();//初始化
	//editDiet.value = unitJson.measure.toString();///初始化
}
//根据单位获取选中的单位json
const getUnitJson = (unit:string) => {
	for(let i=0;i<editDiet.value.unitList.length;i++){
		if(unit==editDiet.value.unitList[i].dw)return editDiet.value.unitList[i];
	}
	return {};
}
const showDateTable = () => {
	onChangeMoon(selectDate.value);//查询需要高亮显示的日期
	datePopup.value.open()
}
//日期选择器月份变更时操作
const onChangeMoon = (date:any) => {
	markDate.value = [];
	let param = {
		userId:userData.id,
		type:menuSelect.value+1,
		groupId:groupId.value,
		recordDate:moment(date).format("YYYY-MM-DD"),
	}
	getGroupFoodDate(param).then((res:any) => {
		res.data.forEach((item:any) => {
			markDate.value.push(item.recordDate)
		})
	})
}
//计算热量
const count = (str:string) => {
	if(str!=="del"){
		if(str==="."){
			if(editEatGrams.value.indexOf(".")===-1)editEatGrams.value += str
		}else{
			let a = editEatGrams.value + str;
			if(Number(a)>999){
				uni.showToast({
				    icon: "none",
				    title: '最大数量999',
				    duration: 1500,
				});
			}else{
				editEatGrams.value += str
			}
		}
	}else{
		editEatGrams.value = editEatGrams.value.toString().slice(0, -1);
	}
	//第一位是0则去掉0
	if(editEatGrams.value.indexOf(".")===-1&&editEatGrams.value.length===2&&editEatGrams.value.indexOf("0")===0){
		editEatGrams.value = editEatGrams.value.slice(1);
	}
	//热量计算
	if(editEatGrams.value==""){
		editHeat.value = 0;
	}else{
		let unitJson = getUnitJson(editDiet.value.unitUnit);
		let cardinal = new BigNumber(unitJson.heat).div(new BigNumber(unitJson.measure));
		editHeat.value = cardinal.times(new BigNumber(editEatGrams.value)).toNumber().toFixed()
	}
}
//变更收藏状态
const onCollect = () => {
	let params = {
		userId:userData.id,
		code:editDiet.value.code,
		optType:!editDiet.value.isCollect
	}
	editFoodCollect(params).then((res:any) => {
		if(res.success){
			let title = " 已收藏";
			if(!params.optType) title = " 已取消收藏";
			uni.showToast({
			    title: title,  
			    icon: 'none',  
			    duration: 1500,
			});
			//console.log(getDietObj(params.code))
			//getDietObj(params.code).isCollect = params.optType;
			editDiet.value.isCollect = params.optType;
		}else{
			uni.showToast({
			    title: res.message,  
			    icon: 'none',  
			    duration: 1500,
			});
		}
	})
}
//加入购物车或确认修改
const addCart = () => {
	if(editEatGrams.value==null||editEatGrams.value==""||editEatGrams.value==0){
		uni.showToast({
		    icon: "none",
		    title: '请输入数量',
		    duration: 1500,
		});
		return
	}
	editDiet.value.unit = editEatGrams.value;
	editDiet.value.heat = editHeat.value;
	editPopup.value.close();
	
	let result = dietCart.value.filter((item:any) => item.code === editDiet.value.code);
	if(result.length === 0){
		dietCart.value.push(editDiet.value)
	}else{
		for(let i=0;i<dietCart.value.length;i++){
			if(dietCart.value[i].code==editDiet.value.code){
				dietCart.value[i]=editDiet.value;
				break;
			}
		}
	};
	countCartHeat();//已选择的总热量
	setSelect();//
}
//计算购物车总热量
const countCartHeat = () => {
	cartHeat.value = 0;
	dietCart.value.forEach((item:any) => {
		cartHeat.value += Number(item.heat);
	});
}
//设置选中状态
const setSelect = () => {
	pageData.value.forEach((item:any) => {
		item?.childNode.forEach((items:any) => {
			items.isCheck = false;
			for(let i=0;i<dietCart.value.length;i++){
				if(item.code == "6666666"){
					if(items.name == dietCart.value[i].name){
						items.isCheck = true;
						break;
					}
				}else{
					if(items.code == dietCart.value[i].code){
						items.isCheck = true;
						break;
					}
				}
				/*
				if(items.code === dietCart.value[i].code){
					items.isCheck = true;
					break;
				}
				*/
			}
		})
	})
	
	search_childNode.value.forEach((items:any) => {
		items.isCheck = false;
		for(let i=0;i<dietCart.value.length;i++){
			if(items.code === dietCart.value[i].code){
				items.isCheck = true;
				break;
			}
		}
	})
}
//弹出选中框
const checkPopup = ref();
const showCheck =  () => {
	if(dietCart.value.length === 0)return;
	if(!checkPopup.value.showPopup){
		checkPopup.value.open()
	}else{
		checkPopup.value.close()
	}
}
//修改购物车
const showEdit = (diet:any) => {
	if(diet.addType === 0){
		editDiet.value = JSON.parse(JSON.stringify(diet));
		editPopup.value.open();
		editEatGrams.value = editDiet.value.unit.toString();
		editHeat.value = editDiet.value.heat;
	}
	if(diet.addType === 1){
		addFormData.value = diet;
		addFormData.value.isEdit = true
		addPopup.value.open()
	}
	//adjustSort();
}

//添加自定义饮食相关功能
const addPopup = ref();
const addFormData = ref();
const showAddCustom = () => {
	if(addDisable.value)return;
	let code = Math.floor(Date.now() * Math.random()).toString();
	addFormData.value = {
		code:code,
		name:"",
		unit:"",
		unitUnit:"克",
		heat:"",
		heatUnit:"千卡",
		addType:1//用户自定义添加
	}
	addPopup.value.open();
}
const addRules: any = ref({
	name: {
		rules: [{
				required: true,
				errorMessage: "请输入名称",
			},
			{
				minLength: 2,
				maxLength: 20,
				errorMessage: '名称长度在 {minLength} 到 {maxLength} 个字符',
			}
		]
	},
	unit: {
		rules: [{
				required: true,
				errorMessage: "请输入单位",
			},
			{
				format:"number",
				errorMessage: "单位必须是数字",
			},
			{
				pattern: /^\d+$/,
				errorMessage: "单位必须是整数",
			},
			{
				minimum: 1,
				errorMessage: "单位最小值是1",
			}
		]
	},
	heat: {
		rules: [{
				required: true,
				errorMessage: "请输入总热量",
			},
			{
				pattern: /^\d+$/,
				errorMessage: "总热量必须是整数",
			},
			{
				format:"number",
				errorMessage: "总热量必须是数字",
			},
			{
				minimum: 5,
				errorMessage: "总热量最小值是5",
			}
		]
	}
})
const addForm = ref();
//添加修改自定义饮食
const addEditCustom = () => {
	addForm.value.validate().then(()=>{
		if(addFormData.value.heatUnit=="千焦"){
			addFormData.value.heat = heatConvert(addFormData.value.heat);
			addFormData.value.heatUnit = "千卡";
		}
		addFormData.value.eatGrams = addFormData.value.unit;
		addFormData.value.foodHeat = addFormData.value.heat;
		
		let result = dietCart.value.filter((item:any) => item.addType == 1 && item.name === addFormData.value.name);
		if(result.length === 0){
			dietCart.value.push(addFormData.value)
		}else{
			for(let i=0;i<dietCart.value.length;i++){
				if(dietCart.value[i].name==addFormData.value.name){
					dietCart.value[i]=addFormData.value;
					break;
				}
			}
		};
		addPopup.value.close();
		
		let custom = pageData.value.filter((item:any) => item.code == '6666666');
		if(custom.length>0){
			let customRow =  custom[0].childNode.filter((item:any) => item.name == addFormData.value.name);
			if(customRow.length>0)customRow[0].isCheck = true;
		}
		
		countCartHeat();
	}).catch((err: any) =>{
		console.log('表单错误信息：', err);
	})
}
//热量单位转换
const heatConvert = (heat:number) => {
	let i = Math.round(new BigNumber(heat).times(new BigNumber(0.2389)).toNumber());
	if(isNaN(i))i=0;
	return i;
}
//删除购物车中项目
const delCheck = (obj:any) => {
	let idx = dietCart.value.indexOf(obj);
	if (idx !== -1){
		dietCart.value.splice(idx, 1);
		countCartHeat();
		setSelect();
	}
	if(dietCart.value.length==0)checkPopup.value.close();
}
const submit = () => {
	if(dietCart.value.length==0&&!isNullAdd){
		uni.showToast({
		    title: "请先选择食物！",  
		    icon: 'none',  
		    duration: 1500,
		});
		return;
	}
	let userHealthRecordDetails:any = [];
	dietCart.value.forEach((item:any) => {
		let code = item.code;
		if(item.addType===1) code = "";
		userHealthRecordDetails.push({
			foodId:code,
			foodName:item.name,
			eatGrams:item.unit,
			foodHeat:item.foodHeat,
			eatHeatQuantity:item.heat,
			unit:item.unitUnit,
		});
	})
	//return;
	let param = {
		total:cartHeat.value,
		groupId:groupId.value,
		userId:userData.id,
		recordDate:moment(selectDate.value).format("YYYY-MM-DD"),
		type:menuSelect.value+1,
		img:imageUrlList.value.toString(),
		userHealthRecordDetails:userHealthRecordDetails
	}
	addGroupFoodRecord(param).then((res:any) => {
		if(res.success){
			checkPopup.value.close();
			//goBack();
			uni.navigateBack({
				success:()=>{
					uni.showToast({
					    title: tabs.value[menuSelect.value]+'打卡成功',  
					    icon: 'success',  
					    duration: 1500,
					});
					getDietRecord();
				}
			});
		}else{
			uni.showToast({
			    title: res.message,  
			    icon: 'none',  
			    duration: 1500,
			});
		}
	})
}
//查询用户饮食记录
const getDietRecord = () => {
	let date = moment(selectDate.value).format("YYYY-MM-DD");
	let param = {
		userId:userData.id,
		type:menuSelect.value+1,
		groupId:groupId.value,
		recordDate:date,
	}
	//console.log(groupId.value)
	getGroupFoodRecord(param).then((res:any) => {
		if(res.success){
			imageUrlList.value = imageConvertArray(res.data.img);
			
			let dietCartData:any = [];
			res.data.userHealthRecordDetails?.forEach((item:any) => {
				let addType = 0;
				let row = getDietInfo(item.foodId);
				if(item.foodId===""){
					addType = 1;
					row.name = item.foodName;
					row.unit = item.eatGrams;
					row.unitUnit = item.unit;
					row.heat = item.eatHeatQuantity;
					row.heatUnit = '千卡';
				}else{
					//console.log(getDietByCode(item.foodId))
					row.unitList = getUnitList(getDietInfo(item.foodId));
					row.code = item.foodId;
					row.heat = item.eatHeatQuantity;
					row.unitUnit = item.unit;
					row.unit = item.eatGrams;
				}
				row.addType = addType;//用户自定义添加
				dietCartData.push(row);
			})
			dietCart.value = dietCartData;
			
			if(dietCart.value.length>0)isNullAdd = true;
			
			nextTick(() => {
				//首次加载购物车有数据，直接弹出
				if(isLoad){
					isLoad = false;
					if(dietCart.value.length>0){
						checkPopup.value.open();
					}
				}
			})
			countCartHeat();
			setSelect();
		}
	})
	/*
	queryClockDetail({userId:userData.id,groupId:groupId.value}).then((res:any) => {
		console.log(res)
	})
	*/
	/*
	getIsFoodRecordList({userId:userData.id,recordDate:date}).then((res:any) => {
		if(res.success){
			                console.log(res);
			isFoodRecordList.value = res.data;
		}
		//console.log(res)
	})
	*/
} 
//更具code获取食物json对象
const getDietInfo = (code:number) => {
	for(let i=0;i<pageData.value.length;i++){
		for(let j=0;j<pageData.value[i].childNode.length;j++){
			let obj = pageData.value[i].childNode[j];
			if(obj.code == code) return JSON.parse(JSON.stringify(obj));
		}
	}
	return {};
}
//判断添加按钮是否可用
const addDisable = ref(false);//添加按钮是否可用
const isAddDisable = () => {
	//设置多少天内可修改
	var threeDaysAgo = moment().subtract(3, 'days');  
	var today = moment();  
	
	var dateToCheck = moment(selectDate.value); // 这是你要检查的日期  
	  
	if (dateToCheck.isBetween(threeDaysAgo, today)) {  
		addDisable.value = false;
	} else {  
		addDisable.value =  true;
		uni.showToast({
		    title: "三天前记录仅可查看",  
		    icon: 'none',  
		    duration: 2000,
		});
	}
}
const popup = ref();
const delRow = ref();
const onCheck = (row:any) => {
	if(addDisable.value)return;
	if(row.isCheck){
		if(row.code==null){
			let dietCartObj = dietCart.value.filter((item:any) => item.addType == 1 && row.name == item.name);
			delRow.value = dietCartObj[0]
		}else{
			let dietCartObj = dietCart.value.filter((item:any) => item.addType == 0 && row.code == item.code);
			delRow.value = dietCartObj[0]
		}
		/*
		for(let i=0;i<dietCart.value.length;i++){
			if(row.code === dietCart.value[i].code){
				delRow.value = dietCart.value[i];
				break;
			}
		}
		*/
		openPopup();
	}else{
		showAddCart(row);
	}
}
const openPopup = () => {
    popup.value.open("bottom");
};

const closePopup = () => {
    popup.value.close();
};
const delChoose = () => {
	/*
	let idx = dietCart.value.findIndex((item:any) => item.code === delRow.value.code);
	*/
   let idx = -1;
   if(delRow.value.addType==1){
   	idx = dietCart.value.findIndex((item:any) => item.addType==1 && item.name === delRow.value.name);
   }
   if(delRow.value.addType==0){
   	idx = dietCart.value.findIndex((item:any) => item.addType==0 && item.code === delRow.value.code);
   }
	if (idx !== -1){
		dietCart.value.splice(idx, 1);
		countCartHeat();
		setSelect();
	}
	popup.value.close();
}
//-------------------------------------------------------------------------------------------------------
//图片预览
const preview = ref();
const previewImage = (id:string,index:number,urls:any) => {
	uni.createSelectorQuery().select(`#${id}${index}`).boundingClientRect().exec((ret)=>{
		//e.callback(ret[0])
		let params = {
			startInfo:[ret[0]],//图片的初始大小与位置
			idPre:id,
			index:index,//当前图片地址
			urls:getHDImages(urls),//预览集合图片地址
		}
		preview.value.open(params);
	});
}
const imageChange = (e:any) => {
	try{
		uni.createSelectorQuery().select(`#${e.id}${e.index}`).boundingClientRect().exec((ret)=>{
			uni.$emit("imagePreviewUpdate",ret[0])
		});
	}catch(e){
		uni.$emit("imagePreviewUpdate",null)
	}
}
//图片上传
const imageUrlList:any = ref([])
const imageUpload = () => {
	chooseImage({
		count:1,
	    success: (chooseImageRes:any) => {
	        const token = uni.getStorageSync("api_token");
	        const tempFilePaths = chooseImageRes.tempFilePaths;
	        showLoading();
	        uni.uploadFile({
	            header: {
	                token,
	            },
	            url: `${BASE_URL}/file/upload`, //仅为示例，非真实的接口地址
	            filePath: tempFilePaths[0],
	            name: "file",
	            formData: {
                    'isCompress':1,
                },
	            success: (uploadFileRes) => {
	                let res: any;
	                 closeLoading();
	                try {
	                    res = JSON.parse(uploadFileRes.data);
	                } catch (error) {
	                    uni.showToast({
	                        icon: "none",
	                        title: '请稍后再试',
	                        duration: 1500,
	                    });
	                    return;
	                }
	                const { flag, data } = res;
	                if (flag !== 1) {
	                    uni.showToast({
	                        icon: "none",
	                        title: '上传失败,请稍后再试',
	                        duration: 1500,
	                    });
	                    return;
	                }
	                const { fileUrl } = data;
	                imageUrlList.value.push(fileUrl);
	            },
	            fail() {
	                closeLoading();
	                uni.showToast({
	                    icon: "none",
	                    title: '上传失败,请稍后再试',
	                    duration: 1500,
	                });
	            },
	        });
	    },
	});
}
const delImage = (index:number) => {
	imageUrlList.value.splice(index, 1);
}
const editChange = (e:any) => {
	//关闭后刷新收藏页
	if(!e.show){
		getFavoritesFood({userId:userData.id}).then((res:any) => {
			let collectAndCommonList =  res.data.list;
			let collectList = collectAndCommonList.filter((node:any) => node.note == 0);
			collectAndCommonList.forEach((item:any) => {
				item.isCheck = false;//是否选中
				let result = dietCart.value.filter((items:any) => items.code === item.code);
				if(result.length>0)item.isCheck = true;
				
				//判断是否收藏
				item.isCollect = false;
				let is = collectList.filter((items:any) => items.code === item.code);
				if(is.length>0){
					item.isCollect = true;//是否收藏
				}
			});
			pageData.value.filter((item:any) => item.code=="9999999")[0].childNode = collectAndCommonList;
			//pageData.value[0].childNode = collectAndCommonList;
			//设置收藏状态
			for(let i=1;i<pageData.value.length;i++){
				for(let j=0;j<pageData.value[i].childNode.length;j++){
					let obj = pageData.value[i].childNode[j];
					if(obj.code == editDiet.value.code){
						obj.isCollect = editDiet.value.isCollect;
					}
				}
			}
		});
	}
}

/*--------搜索----------------------------------------------------------------------------------------*/

const searchText = ref('');
const search_childNode:any = ref([]);


watch(searchText, (newVal: any, oldVal: any) => {
    let str = newVal.trim();
    if (!str) {
        str = "";
        search_childNode.value = [];
        return
    }

    SearchFood();
});

const setSearchSelect = () => {
	search_childNode.value.forEach((items:any) => {
		items.isCheck = false;
		for(let i=0;i<dietCart.value.length;i++){
			if(items.code === dietCart.value[i].code){
				items.isCheck = true;
				break;
			}
		}
	})
}


const SearchFood = async() => {
    //const result_childNode = [];

    const res:any = await searchFood({name:searchText.value.trim()})

    //result_childNode = res.data;
    if(res.flag!==1){
        uni.showToast({
            icon: "none",
            title: "搜素失败,请重新输入",
            duration: 1500,
        });
        return;
    }

    search_childNode.value = matchTextHighLight(res.data);
    setSearchSelect();
};

const matchTextHighLight = (arr:any) => {
    const reg = new RegExp(searchText.value, "gi");
    return arr.map((item:any) => {
        const obj = {
            ...item,
        };
        // const str = `<div style="color:#555;">${item.profile.nick}</div>`;
        const str = item.name
        const nodes = `<div style="color:#333;font-size:30rpx;font-weight:400;">${str.replace(
            reg,
            (s: any) => {
                return `<span style="color:#23e2a6;font-size:30rpx;font-weight:400;">${s}</span>`;
            }
        )}</div>`;
        obj.nodes = nodes;
        return obj;
    });
};

const goFoodDetail = (code:string) => {
    if (!code) {
        return;
    }
    uni.navigateTo({
        url: `/pages/dietMenu/foodDetail?code=${code}`,
    });
};
</script>

<style lang="scss" scoped>
@import './dietGroupMenu.scss';
.right-b{
    width:20rpx;
    height:20rpx;
    margin-left:10rpx;
}
</style>
